#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import json
import jenkins

try:
    form_data = json.loads(sys.argv[1])
except Exception as e:
    print("waring: ", e)



# form_data = {"id": 23, "title": "test", "priority": 1, "form_data": [{"project_branch": "DEPLOY_PROD", "project_name": "work-order-system"}]}

project_name = form_data["form_data"][0]["project_name"]
project_environment = form_data["form_data"][0]["project_environment"]
project_branch = form_data["form_data"][0]["project_branch"]


server = jenkins.Jenkins(
    'http://101.42.13.214:8080',
    username='admin',
    password='wzzkj123'
)

server.build_job(
    name=project_name,
    parameters={"CHANGE_TYPE": project_environment, "gitlabSourceBranch": project_branch}
)